package cn.com.clearbus.controller;

import cn.com.clearbus.service.client.UserServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RefreshScope
public class ClientController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    UserServiceClient userServiceClient;



    @GetMapping(value = "/client/getInfo")
    public Object getInfo(){
        //String url = "http://CLEARBUS-USER/user/getUser?id=123";
        //String url = "http://CLEARBUS-USER/user/getUser?id="+id;  //CLEARBUS-USER是eureka上的服务名,不需要填写多余的端口号
        //return this.restTemplate.getForObject(url, String.class);
        return  userServiceClient.discovery();
    }

    @GetMapping(value = "/client/getInfo2")
    public String getInfo2(@RequestParam("id") String id){
        //String url = "http://CLEARBUS-USER/user/getUser?id=123";
        String url = "http://CLEARBUS-USER/user/getUser?id="+id;  //CLEARBUS-USER是eureka上的服务名,不需要填写多余的端口号
        return this.restTemplate.getForObject(url, String.class);
    }
}
